package com.apexedu.biz.webservice;

import com.apexedu.biz.entity.client.CommandResult;
import com.apexedu.biz.service.impl.AuthShmyServiceImpl;
import com.apexedu.support.spring.SpringUtil;
import com.apexedu.util.json.JsonUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.jws.WebMethod;
import javax.jws.WebService;

/**
 * 对外发布的 webservice
 * User: chenlu
 * Date: 16-05-13  下午4:29
 */
@WebService()
public class AuthWebShmyService {

    private static final Log LOG = LogFactory.getLog(AuthWebShmyService.class);

    /**
     * 下载指定用户信息
     * @param synchronizationtime 同步时间 空值查全部
     * @param clientAppId 所属系统的接入号
     * @return
     */
    @WebMethod
    public CommandResult getResourcesByStu(String clientAppId,String synchronizationtime ) {
        AuthShmyServiceImpl service = (AuthShmyServiceImpl) SpringUtil.getBean("authShmyServiceImpl");
        CommandResult result;
        String jsonstr="";
        try {
            System.out.println("getResourcesByStu-begin"+clientAppId);
            result = service.getResourcesByStu(clientAppId, synchronizationtime);
            System.out.println("getResourcesByStu-end"+synchronizationtime);
        } catch (Exception e) {
            LOG.error(e);
            result = new CommandResult();
            result.setHasError(true);
            result.setError(e.getMessage());
        }
        return result;
    }

    /**
     * 下载指定用户信息
     * @param synchronizationtime 同步时间 空值查全部
     * @param clientAppId 所属系统的接入号
     * @return
     */
    @WebMethod
    public CommandResult getResourcesByJzg(String clientAppId,String synchronizationtime ) {
        AuthShmyServiceImpl service = (AuthShmyServiceImpl) SpringUtil.getBean("authShmyServiceImpl");
        CommandResult result;
        String jsonstr="";
        try {
            System.out.println("getResourcesByJzg-begin"+clientAppId);
            result = service.getResourcesByJzg(clientAppId, synchronizationtime);
            System.out.println("getResourcesByJzg-end"+synchronizationtime);
        } catch (Exception e) {
            LOG.error(e);
            result = new CommandResult();
            result.setHasError(true);
            result.setError(e.getMessage());
        }
        return result;
    }

    /**
     * 下载指定单位信息
     * @param clientAppId 所属系统的接入号
     * @return
     */
    @WebMethod
    public CommandResult getResourcesByOrg(String clientAppId ) {
        AuthShmyServiceImpl service = (AuthShmyServiceImpl) SpringUtil.getBean("authShmyServiceImpl");
        CommandResult result;
        String jsonstr="";
        try {
            System.out.println("getResourcesByOrg-begin"+clientAppId);
            result = service.getResourcesByOrg(clientAppId);
            System.out.println("getResourcesByOrg-end");
        } catch (Exception e) {
            LOG.error(e);
            result = new CommandResult();
            result.setHasError(true);
            result.setError(e.getMessage());
        }
        return result;
    }

    /**
     * 下载指定用户信息
     * @param synchronizationtime 同步时间 空值查全部
     * @param clientAppId 所属系统的接入号
     * @return
     */
    @WebMethod
    public String getResourcesByStuJson(String clientAppId,String synchronizationtime ) {
        AuthShmyServiceImpl service = (AuthShmyServiceImpl) SpringUtil.getBean("authShmyServiceImpl");
        CommandResult result;
        String jsonstr="";
        try {
            System.out.println("getResourcesByStu-begin"+clientAppId);
            result = service.getResourcesByStu(clientAppId, synchronizationtime);
            jsonstr= JsonUtil.getJSONString(result.getStuDsfjcs());
            System.out.println("getResourcesByStu-end"+synchronizationtime);
        } catch (Exception e) {
            LOG.error(e);
            result = new CommandResult();
            result.setHasError(true);
            result.setError(e.getMessage());
        }
        return jsonstr;
    }

    /**
     * 下载指定用户信息
     * @param synchronizationtime 同步时间 空值查全部
     * @param clientAppId 所属系统的接入号
     * @return
     */
    @WebMethod
    public String getResourcesByJzgJson(String clientAppId,String synchronizationtime ) {
        AuthShmyServiceImpl service = (AuthShmyServiceImpl) SpringUtil.getBean("authShmyServiceImpl");
        CommandResult result;
        String jsonstr="";
        try {
            System.out.println("getResourcesByJzg-begin"+clientAppId);
            result = service.getResourcesByJzg(clientAppId, synchronizationtime);
            jsonstr= JsonUtil.getJSONString(result.getJzgDsfjcs());
            System.out.println("getResourcesByJzg-end"+synchronizationtime);
        } catch (Exception e) {
            LOG.error(e);
            result = new CommandResult();
            result.setHasError(true);
            result.setError(e.getMessage());
        }
        return jsonstr;
    }

    /**
     * 下载指定单位信息
     * @param clientAppId 所属系统的接入号
     * @return
     */
    @WebMethod
    public String getResourcesByOrgJson(String clientAppId ) {
        AuthShmyServiceImpl service = (AuthShmyServiceImpl) SpringUtil.getBean("authShmyServiceImpl");
        CommandResult result;
        String jsonstr="";
        try {
            System.out.println("getResourcesByOrg-begin"+clientAppId);
            result = service.getResourcesByOrg(clientAppId);
            jsonstr= JsonUtil.getJSONString(result.getOrgDsfjcs());
            System.out.println("getResourcesByOrg-end");
        } catch (Exception e) {
            LOG.error(e);
            result = new CommandResult();
            result.setHasError(true);
            result.setError(e.getMessage());
        }
        return jsonstr;
    }
}
